package com.shaozi.nc.data.mongodao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.shaozi.data.mongo.dao.SZMongoBaseDao;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.nc.data.model.AttendanceDateInitSyncModel;

@Repository("attendanceMDao")
public class AttendanceMDao extends SZMongoBaseDao<AttendanceDateInitSyncModel> {

	@Autowired
	public AttendanceMDao(MongoTemplate shaoziTemplate) {
		super(shaoziTemplate);
	}


	public void save(String companyId, AttendanceDateInitSyncModel model) throws SzException {
		if (model == null)
			return;
		if (StringUtils.isEmpty(model.getId()))
			model.setCreateTime(System.currentTimeMillis());
		super.save(model, companyId);
	}

	public List<AttendanceDateInitSyncModel> getDateSync(String companyId, long dateBegin,int isSucc) throws SzException {
		Criteria c = new Criteria("dateBegin").is(dateBegin);
		c.and("isSucc").is(isSucc);
		Query query = new Query(c);
		return getMongoTemplate().find(query, AttendanceDateInitSyncModel.class, getCollectionName(companyId));
	}
}
